package sample.dao.article.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import sample.intf.article.dao.IArticleDao;
import sample.intf.article.dto.TArticle;

@Repository
public class ArticleDao implements IArticleDao {

	private static final String NAMESPACE = "sample.article.";

	@Autowired
	SqlSessionTemplate sqlSessionTemplate;

	@Override
	public TArticle selectArticle(long id) {
		return sqlSessionTemplate.selectOne(NAMESPACE + "selectArticleById", id);
	}
	
	@Override
	public List<TArticle> selectAllArticles() {
		return sqlSessionTemplate.selectList(NAMESPACE + "selectAllArticles");
	}

	@Override
	public void insertArticle(TArticle article) {
		sqlSessionTemplate.insert(NAMESPACE + "insertArticle", article);
	}

	@Override
	public boolean updateArticle(TArticle article) {
		return 0 != sqlSessionTemplate.update(NAMESPACE + "updateArticle", article);
	}

	@Override
	public void deleteArticle(long id) {
		sqlSessionTemplate.delete(NAMESPACE + "deleteArticleById", id);
	}
}
